﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Configuration;
using RestSharp;
using WorkBasket.Data.Entities;
namespace WorkBasket.Infrastructure
{
    public class Emailer
    {
        private SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"]);

        public Emailer(){}
 


        public void TestMail()
        {
            var SmtpClient = new SmtpClient();
            SmtpClient.Send("Support@myworkbasket.com", "tadmcclellan@gmail.com", "test subject", "test body");

        }
        public void SendMail(Email email)
        {
            SendMail(email.To, email.Subject, email.Body, email.From);
        }
 
        public void SendMail(string To, string subject, string Message, string From = "postmaster@myworkbasket.com")
        {
            RestClient client = new RestClient();
            client.BaseUrl = "https://api.mailgun.net/v2";
            client.Authenticator =
                    new HttpBasicAuthenticator("api",
                                               ConfigurationManager.AppSettings["mailgun:pvtkey"]);
            RestRequest request = new RestRequest();
            request.AddParameter("domain",
                                 "samples.mailgun.org", ParameterType.UrlSegment);
            request.Resource = "myworkbasket.com/messages";
            request.AddParameter("from", From);
            request.AddParameter("to", To);
            request.AddParameter("subject", subject);
            request.AddParameter("text", Message);
            request.Method = Method.POST;
            IRestResponse r = client.Execute(request);

        }




    }
}